<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 转换二维数组 -->
    <script>
      var findMatrix = function (nums) {
        nums.sort((a, b) => a - b)
        let cur = 0
        let ans = [[nums[0]]]
        for (let i = 1; i < nums.length; i++) {
          if (nums[i] == nums[i - 1]) {
            cur++
            ans[cur] == null ? (ans[cur] = [nums[i]]) : ans[cur].push(nums[i])
          } else {
            cur = 0
            ans[cur].push([nums[i]])
          }
        }
        return ans
      }
      console.log(findMatrix([1, 3, 4, 1, 2, 3, 1]))
    </script>
  </body>
</html>
